package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class remove_cheakdate_class
 */
@WebServlet("/remove_checkdate_class")
public class remove_checkdate_class extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public remove_checkdate_class() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String centername = request.getParameter("centername");
		String classname = request.getParameter("classname");
		// 根据要删除班级的某一天的签到的班级名，将这个班级的对应的签到表中的列属性获得
		String findtable = "select * from information_schema.columns where table_name='" + centername + classname
				+ "check'";
		ArrayList<String> al = new ArrayList<String>();
		Jdbc ft = new Jdbc();
		int count = 1;
		// 因为columns_name中第7个才是需要的日期值，所以用count来计数当count=5时才开始添加
		try {
			ft.Jdbc_Q2(findtable);
			while (ft.rs.next()) {
				if (count <= 6) {
					count++;
				} else
					al.add(ft.rs.getString("column_name"));
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("datelist", al);
		request.getRequestDispatcher("remove_checkdate.jsp?classname="+classname+"&centername="+centername+"").forward(request, response);
	}

}
